Component({
  properties: {
    product: {
      type: Object,
      value: {}
    }
  },

  methods: {
    handleAddToCart() {
      const { product } = this.properties;
      const app = getApp();
      const cartItems = app.globalData.cartItems;
      
      const existItem = cartItems.find(item => item.id === product.id);
      if (existItem) {
        existItem.quantity += 1;
      } else {
        cartItems.push({
          id: product.id,
          name: product.name,
          price: product.price,
          image: product.image,
          quantity: 1
        });
      }
      
      app.globalData.cartItems = cartItems;
      wx.showToast({
        title: '已添加到购物车',
        icon: 'success'
      });
    }
  }
}); 